Add unionTypes and interfaceTypes to the json-modern IR#2050
Conversation
14c4570 to
2def792
Compare
|
|
||
| this.typesUsedSet = new Set(); | ||
| this.unionTypesSet = new Set(); | ||
| this.interfaceTypesMap = new Map(); |
There was a problem hiding this comment.
why are the union types a set and the interface types a map?
There was a problem hiding this comment.
@designatednerd There's a slight difference in the details that union types and interface types give us access to. For the union types, we want to list the union type name, and the types that make up that union. graphql-js supports this out of the box by giving GraphQLUnionType's a types property, which holds the array of types that make up the union. Because of this, we can just store the GraphQLUnionType's in a Set. When the serializeToJSON function is then called to write out the IR as JSON, we can access the union types we want to show by calling getTypes() on each GraphQLUnionType itself.
GraphQLInterfaceType's are handled a bit differently though. graphql-js doesn't provide a types property (or something similar) that gives us easy access to every type using a specific interface. We have to get this ourselves. There was already a helper method setup in the Compiler class (in index.ts) to do this, called possibleTypesForType. Since it's already there in the compiler, I think it makes sense to leverage it, and pass both the interface type, and the types using that interface, through to the serializeToJSON function using a Map.
I'm happy to handle this differently of course. Thanks!
There was a problem hiding this comment.
was mostly curious, thanks for the explanation
| \\"name\\": \\"Character\\", | ||
| \\"types\\": [ | ||
| \\"Human\\", | ||
| \\"Droid\\" |
There was a problem hiding this comment.
Isn't there also an Alien type? Or is this going to only have the possible types that are actually used?
There was a problem hiding this comment.
@designatednerd The schema the tests are using doesn't have an Alien type. You can see it here.
This commit adds new top level properties called `unionTypes` and `interfaceTypes`, to the `json-modern` exported IR. These properties list all unions and their types, as well as all interfaces and their implementing types.
2def792 to
54c60ed
Compare
jbaxleyiii
left a comment
There was a problem hiding this comment.
@hwillson one thing we don't support yet is interfaces implementing interfaces for iOS codegen. The CLI was recently updated to support graphql-js 15 where this feature landed if we want to try and add that to a schema for a test and support it here. However I wouldn't block on it if you didn't want to as we can come back to it later
This commit adds new top level properties called
unionTypesandinterfaceTypes, to thejson-modernexported IR. These properties list all unions and their types, as well as all interfaces and their implementing types.